package com.egao.orderB.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.orderB.biz.MaintainFeeBiz;
import com.egao.orderB.entity.Address;
import com.egao.orderB.entity.MaintainFee;
import com.egao.orderB.service.MaintainFeeService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//import com.egao.orderB.mapper.MaintainFeeMapper;
//import javax.transaction.Transactional;

/**
 * 运费维护服务实现类
 * @author : Doman
 * @date : 2020-06-15 14:20:45
 * @version ：1.0
 */
@Service
public class MaintainFeeServiceImpl /*extends ServiceImpl<MaintainFeeMapper, MaintainFee> */implements MaintainFeeService {

	@Autowired
	private MaintainFeeBiz maintainFeeBiz;

    /**
    @Override
    public PageResult<MaintainFee> listPage(PageParam<MaintainFee> page) {
        List<MaintainFee> records = baseMapper.listPage(page);
        return new PageResult<>(records, page.getTotal());
    }

    @Override
    public List<MaintainFee> listAll(Map<String, Object> page) {
        return baseMapper.listAll(page);
    } */

    @Override
    public JsonResult list(PageResult2<T> page, MaintainFee maintainFee, User loginUser)  throws Exception{
        return maintainFeeBiz.list(page,maintainFee,loginUser);
    }
    @Override
    public JsonResult ntlist(PageResult2<T> page, MaintainFee maintainFee, User loginUser)  throws Exception{
        return maintainFeeBiz.ntlist(page,maintainFee,loginUser);
    }

    @Override
    public JsonResult list(MaintainFee maintainFee, User loginUser) {
        //生成拼音的
//        List<MaintainFee> list = maintainFeeBiz.list(maintainFee,loginUser);
//        for (MaintainFee f: list) {
//            if(f.getPinyin()==null || f.getPinyin().equals(""))
//            maintainFeeBiz.update(f,loginUser);
//        }

        //复制数据
//        List<MaintainFee> list = maintainFeeBiz.list(maintainFee,loginUser);
//        for (MaintainFee f: list) {
//            if(f.getDock()!=null && f.getDock().equals("宁波港")){
//                f.setDock("舟山港");
//                f.setPrice((Integer.valueOf(f.getPrice())+1200)+"");
//                f.setCommission((Integer.valueOf(f.getPrice())-Integer.valueOf(f.getDriverPrice()))+"");
//                maintainFeeBiz.save(f,loginUser);
//            }
//        }
        return JsonResult.ok().setData(maintainFeeBiz.list(maintainFee,loginUser));
    }
    @Override
    public JsonResult ntlist(MaintainFee maintainFee, User loginUser) {
        return JsonResult.ok().setData(maintainFeeBiz.ntlist(maintainFee,loginUser));
    }

    @Override
    public JsonResult getById(MaintainFee maintainFee) {
        return JsonResult.ok().setData(maintainFeeBiz.getById(maintainFee));
    }

    @Transactional
    @Override
    public JsonResult save(MaintainFee maintainFee, User loginUser) {
        maintainFeeBiz.save(maintainFee, loginUser);
        maintainFee.setBoxType(maintainFee.getBoxType2());
        maintainFee.setPrice(maintainFee.getPrice2());
        maintainFee.setDriverPrice(maintainFee.getDriverPrice2());
        if (maintainFeeBiz.save(maintainFee, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Override
    public JsonResult update(MaintainFee maintainFee, User loginUser) {
        if (maintainFeeBiz.update(maintainFee, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Override
    public JsonResult remove(MaintainFee maintainFee, User loginUser) {
        if (maintainFeeBiz.remove(maintainFee, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

    @Override
    public List<Address> searchAddressFee(MaintainFee maintainFee, User loginUser) {
        return maintainFeeBiz.searchAddressFee(maintainFee, loginUser);
    }

}
